<?php

class Bai_viet extends Eloquent {
	protected $guarded = array();

	public static $rules = array(
		'tieu_de' => 'required',
		'noi_dung' => 'required',
		'TaiKhoan_Id' => 'required',
		'ChuyenMucBaiViet_Id' => 'required',
		'tag' => '',
		'tom_tat' =>'required',
		'thu_tu_bai_viet' => ''
	);
	public function get_dsbaiviet() {
        $results = DB::table('bai_viets')->orderBy('thu_tu_bai_viet','desc')->get();
        return $results;
    }

	public function get_dsbaiviet_limit() {
        $results = DB::table('bai_viets')->orderBy('thu_tu_bai_viet','desc')->limit(10)->get();
        return $results;
    }

    public function all_post(){
    	$results = DB::table('bai_viets')
			->leftJoin('chuyen_muc_bai_viets','chuyen_muc_bai_viets.id', '=', 'bai_viets.ChuyenMucBaiViet_Id')
			->get();
		return $results;
    }

    public function get_all_tittle()
    {
    	$bai_viet = DB::table('bai_viets')
					    	->orderBy('id','desc')
					    	->limit(10)
					    	->get();
		return $bai_viet;
    }

    public function get_max_thutu()
    {
    	$thu_tu = DB::table('bai_viets')->max('thu_tu_bai_viet');
    	return $thu_tu;
    }
    public function get_min_thutu()
    {
    	$thu_tu = DB::table('bai_viets')->min('thu_tu_bai_viet');
    	return $thu_tu;
    }
}